package com.demo.dubbo.consumer.controller;

import com.alibaba.fastjson.JSONObject;
import com.demo.dubbo.provider.api.service.ITestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
@Api(description = "Dubbo测试")
@RequestMapping("/dubbo")
public class ConsumerController {

    @Reference
    private ITestService iTestService;

    @ApiOperation(value = "dubbo 调用测试")
    @PostMapping("/consumer/test")
    public String consumerTest() {
        return iTestService.getT(new Date().toString());
    }

    @ApiOperation(value = "dubbo 调用测试")
    @PostMapping("/gateway/test")
    public String gatewayTest(HttpServletRequest request) {
        System.out.println(JSONObject.toJSONString(request.getHeader("userinfo")));
        return "222";
    }

}
